// Ofri Keidar 302933981 group 05

package server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Class holds the data of a socket that a client has connected to
 */
public class SocketData {

	private Socket socket;
	private ObjectInputStream inObject; // used to read serialized objects sent by client
	private ObjectOutputStream outObject; // used to write serialized object to client 
	
	/**
	 * Constructor- creates a new SocketData object according to given socket.
	 * Object streams are initialized according to given socket
	 * @param socket- socket connecting to client
	 * @throws IOException if had problems getting object streams from socket
	 */
	public SocketData(Socket socket) throws IOException {
		
		this.socket = socket;
		
		// get streams from socket
		inObject = new ObjectInputStream(socket.getInputStream());
		outObject = new ObjectOutputStream(socket.getOutputStream());		
	}

	/**
	 * Returns the socket connected to client
	 * @return socket attribute
	 */
	public Socket getSocket() {
		return socket;
	}

	/**
	 * Returns the object input stream from the client
	 * @return object input stream attribute
	 */
	public ObjectInputStream getFromClientObjectStream() {
		return inObject;
	}

	/**
	 * Returns the object output stream to the client
	 * @return object output stream attribute
	 */
	public ObjectOutputStream getToClientObjectStream() {
		return outObject;
	}
}